package com.shopping.controller;

import com.shopping.redis.UserKey;
import com.shopping.response.CodeMsg;
import com.shopping.response.Result;
import com.shopping.service.UserService;
import com.shopping.utils.RedisService;
import com.shopping.utils.UUIDUtils;
import com.shopping.utils.ValidataUtils;
import com.shopping.vo.LoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisService redisService;

    @RequestMapping("/to_login")
    public String to_login(String message){
        return "login";
    }

    @RequestMapping("/do_login")
    @ResponseBody
    public Result<Boolean> do_login(HttpServletResponse response, @Valid LoginVO loginVO){
        log.info("loginVO:{}",loginVO);
        //登录
        userService.login(response,loginVO);
//        CodeMsg login = userService.login(loginVO);
//        if(login.getCode()==0){
//            return Result.success(CodeMsg.SUCCESS.getMessage());
//        }
//        else{
//            return Result.error(login);
//        }

        return Result.success(CodeMsg.SUCCESS.getMessage());
    }
}
